import java.util.Arrays;

/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution34 {

    public static void main(String args[]) {
        Solution34 s = new Solution34();
        System.out.println(Arrays.toString(s.searchRange(new int[]{1, 2, 4, 4, 5}, 0)));
    }

    public int[] searchRange(int[] nums, int target) {
        if (nums.length == 0) {
            return new int[]{-1, -1};
        }
        int ret[] = new int[2];
        int l = 0;
        int r = nums.length - 1;
        while (l < r) {
            int mid = (l + r) / 2;
            if (nums[mid] < target) {
                l = mid + 1;
            } else {
                r = mid;
            }
        }
        if (nums[l] == target) {
            ret[0] = l;
        } else {
            return new int[]{-1, -1};
        }

        l = 0;
        r = nums.length - 1;
        while (l < r) {
            int mid = (l + r + 1) / 2;
            if (nums[mid] > target) {
                r = mid - 1;
            } else {
                l = mid;
            }
        }
        ret[1] = l;
        return ret;
    }

}
